package belajarzk.action.report;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.Button;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Iframe;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.Toolbar;
import org.zkoss.zul.Window;

import belajarzk.common.Common;


public class ReportWindow extends Window {

	private String src;

	/**
	 * 
	 */
	private static final long serialVersionUID = -220762105655460942L;

	public ReportWindow(String src) {
		super();
		this.src = src;
		init();
	}

	public ReportWindow(String src, String title, String border,
			boolean closable) {
		super(title, border, closable);
		this.src = src;
		init();
	}

	private void init() {

		setClosable(false);
		setBorder("none");

		setWidth("95%");
		setHeight("95%");
		setPosition("center");

		this.setTitle("Print Preview");
		Common.clear(this);
		Borderlayout borderlayout = new Borderlayout();
		Center center = new Center();
		center.setParent(borderlayout);
		center.setFlex(true);

		Iframe include = new Iframe(src);
		include.setWidth("100%");
		include.setHeight("100%");

		Grid grid = new Grid();
		grid.setParent(center);
		grid.setWidth("100%");
		grid.setHeight("100%");
		
		Rows rows = new Rows();
		rows.setParent(grid);
		Row row = new Row();
		row.setStyle("border:0px;background: transparent;");
		row.setParent(rows);
		row.appendChild(include);

		row = new Row();
		row.setStyle("border:0px;background: transparent;");
		row.setParent(rows);

		Toolbar hbox = new Toolbar();
		hbox.setHeight("40px");
		hbox.setParent(row);
		Button cancel = new Button(Common.getBahasa("common_cancel"), "/img/cancel.gif");
		cancel.addEventListener("onClick", new EventListener() {
			@Override
			public void onEvent(Event arg0) throws Exception {
				ReportWindow.this.detach();
			}
		});
		cancel.setParent(hbox);
		borderlayout.setParent(this);

	}

}
